package com.foruo.learn.designmode.cloneable;

/**
 * 案例对象
 *
 * 1、想要支持对象的clone，对象需要实现 Cloneable
 * 2、并且重写 clone() 方法
 *
 * @author GaoYuan
 * @date 2018/5/14 上午8:54
 */
public class DemoEntity implements Cloneable{

    private String id;
    private String name;
    private String msg;

    public DemoEntity(String msg){
        this.msg = msg;
    }

    public DemoEntity(){}
    
    /**
     * 执行clone
     * 注意，需要考虑到 浅拷贝 与 深拷贝 的情况
     * @author GaoYuan
     * @date 2018/5/14 上午8:56
     */
    @Override
    protected DemoEntity clone(){
        DemoEntity demoEntity = null;
        try{
            demoEntity = (DemoEntity)super.clone();
        }catch (CloneNotSupportedException e){
            e.printStackTrace();
        }
        return demoEntity;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    @Override
    public String toString() {
        return "DemoEntity{" +
                "id='" + id + '\'' +
                ", name='" + name + '\'' +
                ", msg='" + msg + '\'' +
                '}';
    }
}
